package igloo.ui;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JPanel;

public class GradientPanel extends JPanel
{
    private static final long serialVersionUID = 1L;

    private Color mStartColor = getBackground().darker();
    private Color mEndColor = getBackground();

    public Color getStartColor()
    {
        return mStartColor;
    }

    public void setStartColor(Color startColor)
    {
        mStartColor = startColor;
    }

    public Color getEndColor()
    {
        return mEndColor;
    }

    public void setEndColor(Color endColor)
    {
        mEndColor = endColor;
    }

    @Override
    protected void paintComponent(Graphics g)
    {
        if(!isOpaque())
        {
            super.paintComponent(g);
            return;
        }

        Graphics2D g2d = (Graphics2D)g;

        int w = getWidth();
        int h = getHeight();

        GradientPaint paint = new GradientPaint(0, 0, mStartColor, 0, h,
                mEndColor);
        g2d.setPaint(paint);
        g2d.fillRect(0, 0, w, h);

        setOpaque(false);
        super.paintComponent(g);
        setOpaque(true);
    }
}
